package com.netease.financial.common.util.preferences;

import com.netease.financial.common.util.PackageUtils;

/**
 * Created by wyf on 8/3/15.
 */
public class BadgePreferencesHelper {

    private static final String PREFERENCES_FILE_NAME = PreferencesHelper.getFullPreferenceFileName("badge");

    private static final String KEY_UNREAD_PRIVATE_MESSAGE_COUNT = "unread_private_message_count";

    private static PreferencesHelper sPreferencesHelper;

    private static PreferencesHelper getPreferencesHelper() {
        if (sPreferencesHelper == null) {
            sPreferencesHelper = PreferencesHelper.newInstance(PREFERENCES_FILE_NAME);
        }
        return sPreferencesHelper;
    }

    // Asset tab badge is refer to this badge
    public static boolean isUpdateBadgeShouldShow() {
        int latestAppVersionCode = AppUpdatePreferencesHelper.getLatestAppVersionCode();
        int currentAppVersionCode = PackageUtils.getCurrentApkVersionCode(PreferencesHelper.getContext());
        return latestAppVersionCode > currentAppVersionCode;
    }

    public static void setUnreadPrivateMessageCount(int count) {
        getPreferencesHelper().putInt(KEY_UNREAD_PRIVATE_MESSAGE_COUNT, count);
    }

    public static int getUnreadPrivateMessageCount() {
        return getPreferencesHelper().getInt(KEY_UNREAD_PRIVATE_MESSAGE_COUNT, 0);
    }

    // Asset tab badge is refer to this badge
    public static boolean isUnreadPrivateMessageBadgeShouldShow() {
        int unreadSiteMessageCount = getUnreadPrivateMessageCount();
        return unreadSiteMessageCount > 0;
    }

    public static boolean isHomeTabBadgeShouldShow() {
        return false;
    }

    public static boolean isAccountTabBadgeShouldShow() {
        return false;
    }

    public static boolean isProductTabBadgeShouldShow() {
        return false;
    }

    public static boolean isInformationTabBadgeShouldShow() {
        return false;
    }

    public static boolean isAssetTabBadgeShouldShow() {
        return isUpdateBadgeShouldShow() || isUnreadPrivateMessageBadgeShouldShow();
    }
}
